package it.trekker.dataexchange;

import java.util.List;

import it.trekker.converter.IJsonConverter;
import it.trekker.converter.JsonConverter;
import it.trekker.statistics.PoiDistanceStatistics;
import org.teleal.cling.binding.annotations.UpnpAction;
import org.teleal.cling.binding.annotations.UpnpOutputArgument;
import org.teleal.cling.binding.annotations.UpnpService;
import org.teleal.cling.binding.annotations.UpnpServiceId;
import org.teleal.cling.binding.annotations.UpnpServiceType;
import org.teleal.cling.binding.annotations.UpnpStateVariable;

@UpnpService(
		serviceId = @UpnpServiceId("TrekkerDataExchangeServiceId"),
		serviceType = @UpnpServiceType(value = "DataExchangeServiceType", version = 1)
)
public class DataExchange {
	
	@UpnpStateVariable
	private String data;

	@UpnpAction(
			name = "RetrieveData",
			out = @UpnpOutputArgument(name = "DataList", stateVariable = "data")
	)
	public String retrieveData() {
		
		List<PoiRealTimeInfo> pois = PoiDistanceStatistics.getSharedInstance().getPoisList();
		
		if(pois.size() > 0) {
			IJsonConverter converter = new JsonConverter();
			data = converter.PoiRealTimeInfoArray2Json((PoiRealTimeInfo[]) pois.toArray());
		}
		else {
			data = "";
		}
		
		return data;
	}
	
}
